home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1994 January / PSL Monthly Shareware CD-ROM (Public Software Library) (January 1994).iso / games / dos / misc / kaoskey.com / KAOSKEYS.ASM < prev    next >
Encoding:
Assembly Source File  |  1990-05-31  |  8.3 KB  |  278 lines

  1.   
  2. ;██████████████████████████████████████████████████████████████████████████
  3. ;██                                                                      ██
  4. ;██                             KaosKeys v1.0                            ██
  5. ;██                                                                      ██
  6. ;██        Copyright (C) 1990  Philip Maland  All Rights Reserved        ██
  7. ;██                                                                      ██
  8. ;██                        Created:  May 25, 1990                        ██
  9. ;██                                                                      ██
  10. ;██████████████████████████████████████████████████████████████████████████
  11.   
  12.   
  13. Seg_a        Segment
  14.         Assume    cs:Seg_A, ds:Seg_A
  15.   
  16.   
  17.         org    100h
  18.   
  19. Start:
  20.         jmp    Install            ; Go to installation routine
  21.  
  22. ;██████████████████████████████████████████████████████████████████████████
  23. ;██  Int 09h - New Handler                                               ██   
  24. ;██████████████████████████████████████████████████████████████████████████
  25.  
  26. Int_09:
  27.         push    ax            ; Save the world
  28.         push    bx
  29.         push    cx
  30.         push    dx
  31.         push    es
  32.         pushf
  33.  
  34.         in    al,60h            ; Get scan of code key pressed
  35.                         ; into AL
  36.         mov    bl,32h            ; High char to check ('Z')
  37.         mov    bh,10h            ; Low char to check  ('A')
  38.         call    ChrRang            ; Is AL between 'Z' and 'A'?
  39.         jc    End_09            ; No, it isn't an alpha key
  40.  
  41.         mov    bl,1Dh            ; High char
  42.         mov    bh,1Ah            ; Low char
  43.         call    ChrRang            ; Since we are using scan codes
  44.                         ; there are some keys between
  45.                         ; 'A' and 'Z' that aren't alpha
  46.                         ; keys.  This check for one
  47.                         ; set of non-alpha keys.
  48.  
  49.         jnc    End_09            ; Yes, it isn't an alpha key
  50.  
  51.         mov    bl,2Bh            ; High char
  52.         mov    bh,27h            ; Low char
  53.         call    ChrRang            ; This checks for the other set
  54.                         ; of non-alpha keys.
  55.  
  56.         jnc    End_09            ; Yes, it is in this set, so it
  57.                         ; isn't an alpha key.
  58.         
  59.         mov    ax,10            ; Get random number between 1
  60.         push    ax            ; and 10 and push it on the stack
  61.         call    Random            ; Random number between 1 and 
  62.                         ; 10 is returned in AX
  63.         cmp    ax,5            ; Is the number greater than 5?
  64.         jg    End_09            ; Yes, so leave the key alone
  65.  
  66.         mov    ax,0            ; Point ES to low memory (0000)
  67.         mov    es,ax
  68.         mov    al,byte ptr es:[417h]    ; Get shift flags
  69.         test    al,3            ; Are any of the shift keys pressed?
  70.         jz    SetShift        ; If not, turn on the shift flag
  71.                         ; for the right shift key.
  72. ;█
  73. ;  Here we know a shift key is pressed.
  74. ;█
  75.         mov    cs:SaveShift,al        ; Save the shift flags
  76.  
  77.         and    byte ptr es:[417h],11111100b    ; Clear the shift key
  78.                             ; flags.
  79.         jmp    CallRest
  80.  
  81. SetShift:
  82.         mov    cs:SaveShift,al        ; Save the shift flags
  83.         or    byte ptr es:[417h],01    ; Set the right shift key flag
  84.         jmp    CallRest
  85.  
  86. CallRest:
  87.         popf                ; Restore all registers
  88.         pop    es            ; and call the Int 09h handler
  89.         pop    dx
  90.         pop    cx
  91.         pop    bx
  92.         pop    ax
  93.         pushf
  94.         call    dword ptr cs:[Old_09_Ofs]
  95.  
  96.         push    ax            ; Save the regs were gonna use
  97.         push    es
  98.         pushf
  99.  
  100.         mov    ax,0            ; Point ES to low memory again
  101.         mov    es,ax
  102.         mov    al,cs:SaveShift        ; Get the saved flags
  103.         mov    byte ptr es:[417h],al    ; Restore them back to the
  104.                         ; flag status byte in low memory.
  105.  
  106.         popf                ; Restore the registers
  107.         pop    es
  108.         pop    ax
  109.         iret                ; Return from the interrupt
  110.  
  111. End_09:
  112.         popf                ; Restore all registers
  113.         pop    es
  114.         pop    dx
  115.         pop    cx
  116.         pop    bx
  117.         pop    ax
  118.         jmp    dword ptr cs:[Old_09_Ofs]    ; Jump to the old Int 09
  119.                             ; handler
  120.  
  121. SaveShift    db    0            ; Byte to save flags to
  122.  
  123. Old_09_Ofs    dw    0
  124. Old_09_Seg    dw    0
  125.  
  126. ;█████████████████████████████████████████████████████████████████████████████
  127. ;██                                                                         ██
  128. ;██   Procedure:  ChrRang                                                   ██
  129. ;██                                                                         ██
  130. ;██   Call to test if a character is between or included by two characters  ██
  131. ;██                                                                         ██
  132. ;██     To Call:     AL = Char to check                                     ██
  133. ;██                  BL = upper match char                                  ██
  134. ;██                  BH = low match char                                    ██
  135. ;██        Exit:     CF clear if valid match                                ██
  136. ;██                  BL = undefined                                         ██
  137. ;██                       all other registers unchanged                     ██
  138. ;██                                                                         ██
  139. ;█████████████████████████████████████████████████████████████████████████████
  140.  
  141. ChrRang:
  142.         cmp    al,bh        ; Is the char < BH
  143.         jc    ChrRng1        ; Yes, no match, return with carry
  144.         inc    bl        ; Is the char > BL
  145.         cmp    al,bl        ; Compare with upper limit
  146.         cmc            ; Invert the carry flag
  147. ChrRng1:
  148.         ret
  149.  
  150. ;█████████████████████████████████████████████████████████████████████████████
  151. ;██                                                                         ██
  152. ;██   Procedure:  Random                                                    ██
  153. ;██                                                                         ██
  154. ;██     To Call:     SP + 4 = High number for random generator              ██
  155. ;██                                                                         ██
  156. ;██        Exit:     AX = Random number between 0 and AX                    ██
  157. ;██                                                                         ██
  158. ;██                  (Taken from Turbo Pascal Random() function)            ██
  159. ;██                                                                         ██
  160. ;█████████████████████████████████████████████████████████████████████████████
  161.  
  162. Random:
  163.         call    Rnd2
  164.         xor    ax,ax
  165.         mov    bx,sp
  166.         mov    bx,ss:[bx+2]
  167.         or    bx,bx
  168.         jz    RndEnd
  169.         xchg    ax,dx
  170.         div    bx
  171.         xchg    ax,dx
  172.   
  173. RndEnd:
  174.         ret    2
  175.  
  176. Rnd2:
  177.         mov    ax,cs:Data_3
  178.         mov    bx,cs:Data_4
  179.         mov    cx,ax
  180.         mul    cs:data_29
  181.         shl    cx,1
  182.         shl    cx,1
  183.         shl    cx,1
  184.         add    ch,cl
  185.         add    dx,cx
  186.         add    dx,bx
  187.         shl    bx,1
  188.         shl    bx,1
  189.         add    dx,bx
  190.         add    dh,bl
  191.         mov    cl,5
  192.         shl    bx,cl
  193.         add    dh,bl
  194.         add    ax,1
  195.         adc    dx,0
  196.         mov    cs:Data_3,ax
  197.         mov    cs:Data_4,dx
  198.         ret
  199.  
  200. Data_29        dw    8405h
  201.  
  202. Data_3        dw    0
  203. Data_4        dw    0
  204.  
  205. ;██████████████████████████████████████████████████████████████████████████
  206. ;██  Int 2Fh - New Handler                                               ██   
  207. ;██████████████████████████████████████████████████████████████████████████
  208.  
  209. Int_2F:
  210.         cmp    ah,0E0h            ; Is this call for us?
  211.         jne    Continue        ; No, Continue with old Int 2Fh
  212.         cmp    al,00h            ; Yes, Is it an installation
  213.         jne    Continue        ;   check?  No, Continue.
  214.         mov    al,0FFh            ; Yes, set al to FFh 
  215.         iret                ; Interrupt Return
  216.     
  217. Continue:
  218.         jmp    dword ptr cs:[Old_2F_Ofs]    ; If not for us, go on
  219.                             ;   to old Int 2Fh.
  220.  
  221. Old_2F_Ofs    dw    ?            ; Old Int 2Fh Offset
  222. Old_2F_Seg    dw    ?            ; Old Int 2Fh Segment
  223.  
  224.  
  225. ;██████████████████████████████████████████████████████████████████████████
  226. ;██  Installation Routine                                                ██   
  227. ;██████████████████████████████████████████████████████████████████████████
  228.  
  229. Install:
  230.         mov    ax,0E000h        ; Call Int 2F to check for 
  231.         int    2Fh            ;   re-installation
  232.         cmp    al,0FFh            ; Is it already installed?
  233.         je    Installed        ; Yes, Print message and quit
  234.         mov    ax,352Fh        ; No, Get old Int 2F to point 
  235.         int    21h            ;   to our Int 2F handler.
  236.         mov    Old_2F_Ofs,bx        ; Save Old Offset
  237.         mov    Old_2F_Seg,es        ; Save Old Segment
  238.         mov    ax,252Fh        ; Set Int 2F vector to point
  239.         mov    dx,offset Int_2F    ;   to our handler at Int_2F
  240.         int    21h            ; Set it.
  241.  
  242.         mov    ax,3509h        ; Get old Int 09 vector
  243.         int    21h
  244.         mov    Old_09_Ofs,bx        ; Save Old Offset
  245.         mov    Old_09_Seg,es        ; Save Old Segment
  246.         mov    ax,2509h        ; Set keyboard vector to point
  247.         mov    dx,offset Int_09    ; to our handler
  248.         int    21h            ; Set it.
  249.  
  250.         call    Randomize        ; Get random number seed
  251.                         ; (based on the time)
  252.  
  253.         mov    dx,offset Install    ; Set length of program
  254.         int    27h            ; Go TSR
  255.  
  256. Installed:    
  257.         mov    ah,09            ; Print string until '$' or 24h
  258.         mov    dx,offset Message    ; Print data at Message.
  259.         int    21h            ; Print it
  260.         int    20h            ; Quit
  261.  
  262. Randomize:
  263.         mov    ah,2Ch
  264.         int    21h            ; DOS Services  ah=function 2Ch
  265.                         ;  get time, cx=hrs/min, dh=sec
  266.         mov    cs:Data_3,cx
  267.         mov    cs:Data_4,dx
  268.         ret
  269.   
  270. Message        db    'KaosKeys - Copyright (C) 1990 - By Philip Maland',00h
  271.         db    0Ah,0Dh,0Ah,0Dh,'Already installed.',0Ah,0Dh,24h
  272.  
  273. Seg_A        ends
  274.   
  275.   
  276.   
  277.         end    Start
  278.